package mid

import "sort"

func MinimumAddedInteger(nums1 []int, nums2 []int) int {
	m := len(nums1)
	n := len(nums2)
	sort.Ints(nums1)
	sort.Ints(nums2)
	for i := 2; i >= 0; i-- {
		left, right := i+1, 1
		for left < m && right < n {
			if nums1[left]-nums2[right] == nums1[i]-nums2[0] {
				right++
			}
			left++
		}
		if right == n {
			return nums2[0] - nums1[i]
		}
	}
	return 0
}
